package com.sh.suhe.utildemos.dialogUtils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.sh.suhe.utildemos.R;
import com.sh.suhe.utildemos.model.PaPhotoTypeModel;
import com.sh.suhe.utildemos.views.activity.photo.StaggeredItemDecoration;
import com.sh.suhe.utildemos.views.adapter.PaPhotoTypeAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by suhe on 2016/9/7.
 */
public class RightDialog extends Dialog {
    RecyclerView recyclerView;
    PaPhotoTypeAdapter adapter;
    List<PaPhotoTypeModel> types = new ArrayList<>();
    public RightDialog(Context context) {
        super(context,R.style.dialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_right);
        Window win = this.getWindow();
        win.getAttributes().width = LinearLayout.LayoutParams.WRAP_CONTENT;
        win.getAttributes().gravity = Gravity.RIGHT;

//        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
//        params.x = -80;//设置x坐标
//        params.y = -60;//设置y坐标
//        params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
//        params.height = LinearLayout.LayoutParams.MATCH_PARENT;
//        win.setAttributes(params);
        recyclerView = findViewById(R.id.dialog_right_rv);
        int space = 10;
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        //解决item跳动
        layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new StaggeredItemDecoration(space));//单位px

        adapter = new PaPhotoTypeAdapter(this.getContext());
        adapter.setTypeClick(typeClick);
        recyclerView.setAdapter(adapter);
        adapter.setImgTypeList(this.types);
        adapter.notifyDataSetChanged();
    }

    public void setData(List<PaPhotoTypeModel> types) {
        if (types == null){
            return;
        }
        this.types.clear();
        this.types.addAll(types);
//        adapter.setImgTypeList(types);
//        adapter.notifyDataSetChanged();
    }
    TypeClick typeClick;
    public void setTypeClick(TypeClick typeClick) {
        this.typeClick = typeClick;
    }
    public interface TypeClick{
        void clickType(PaPhotoTypeModel position);
    }
}
